package com.huwaiwai001.echo.util;

import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by hww on 2019/3/18 10:46.
 */
public class InputUtil {

    private static final BufferedReader KEYBOARD_INPUT = new BufferedReader(new InputStreamReader(System.in));

    private InputUtil() {
        // do nothing
    }

    /**
     * 获取控制台输入
     * @param prompt 提示语
     * @return
     */
    public static String getString(String prompt) {
        String returnData = null;
        boolean flag = true;

        while (flag) {
            System.err.println(prompt);
            try {
                returnData = KEYBOARD_INPUT.readLine();
                if (StringUtils.isBlank(returnData)) {
                    System.err.println("输入的数据不允许为空!");
                } else {
                    flag = false;
                }
            } catch (Exception e) {
                System.err.println("输入的数据错误!");
            }
        }
        return returnData;
    }

}
